package com.example.yuejian.yuejian.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.TrainInfo;
import com.example.yuejian.yuejian.dialog.CallDialog;
import com.example.yuejian.yuejian.model.TrainModel;
import com.squareup.picasso.Picasso;

public class TrainDetailActivity extends AppCompatActivity {
       private ImageView train_image;
    private TextView train_intro;
    private TextView train_known;
    private TextView train_time;
    private TextView train_address;
    private TextView train_price;
    private TextView train_zixun;
    private Button train_signuo_btn;
    String phone;
    private ImageView btn_back;
    TrainInfo res;
    private ModleListener<TrainInfo>modleListener=new ModleListener<TrainInfo>() {
        @Override
        public void onResponse(TrainInfo o) {
              res =o;
            train_intro.setText(res.getIntro());
            //train_known.setText(res.getNotice());
            train_time.setText(res.getTime());
            train_address.setText(res.getPlace());
            train_price.setText(res.getMoney()+"元");
            phone=res.getPhone();
            if (!"".equals(res.getPhoto()))
            {
                Picasso.with(getApplication()).load(res.getPhoto()).into(train_image);
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_detail);
        initViews();
        initEvents();
        back();
    }
    private void initViews()
    {
        train_image=(ImageView)findViewById(R.id.train_detail_img);
        train_intro=(TextView)findViewById(R.id.train_detail_intro);
        train_known=(TextView)findViewById(R.id.train_detail_known);
        train_time=(TextView)findViewById(R.id.train_detail_time);
        train_address=(TextView)findViewById(R.id.train_detail_address);
        train_price=(TextView)findViewById(R.id.train_detail_price);
        train_zixun=(TextView)findViewById(R.id.train_detail_zixun);
        train_signuo_btn=(Button) findViewById(R.id.train_detail_signup_btn);
    }
    private void getdatas()
    {
        Intent intent=getIntent();
        String train_id=intent.getStringExtra("train_id");
        Toast.makeText(getApplication(),train_id,Toast.LENGTH_SHORT).show();
        TrainModel model=new TrainModel();
        model.Traindetail(train_id,modleListener);
    }
    private void initEvents()
    {
        final CallDialog dialog=new CallDialog();
        train_zixun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.showCallPhoneDialog(TrainDetailActivity.this,phone);
            }
        });

        train_signuo_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(TrainDetailActivity.this,TrainSignActivity.class);
                intent.putExtra("money",res.getMoney());
                intent.putExtra("train_name",res.getTrainname());
                intent.putExtra("train_id",res.getId()+"");
                intent.putExtra("type",res.getTypename());
                startActivity(intent);
            }
        });
    }
    private void back()
    {
        btn_back=(ImageView)findViewById(R.id.imgBtn_train_detail_back);
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    protected void onResume() {
        getdatas();
        super.onResume();
    }
}
